package com.oneguy.control.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * Created by ZuoShu on 16/12/7.
 */
public class TimeUtil {

    // input time  17:31
    public static long toLongTime(String timeString) {
        try {
            SimpleDateFormat formatter = new SimpleDateFormat("HH:mm");
            Date inputDate = formatter.parse(timeString);

            Calendar inputCalendar = Calendar.getInstance();
            inputCalendar.setTime(inputDate);

            Calendar inputCalendar2 = Calendar.getInstance();
            inputCalendar2.setTime(new Date());
            inputCalendar2.set(Calendar.HOUR_OF_DAY,inputCalendar.get(Calendar.HOUR_OF_DAY));
            inputCalendar2.set(Calendar.MINUTE,inputCalendar.get(Calendar.MINUTE));

            Calendar nowCalendar = Calendar.getInstance();
            nowCalendar.setTime(new Date());

            if (inputCalendar2.before(nowCalendar)) {
                inputCalendar2.add(Calendar.DATE, 1);
            }
            return inputCalendar2.getTimeInMillis();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return 0;
    }
}
